package com.deluxelx.soul.inn.common.result;

import lombok.AllArgsConstructor;
import lombok.Data;
import lombok.NoArgsConstructor;

/**
 * 系统统一返回类
 *
 * @author: zihao.liao
 * @date: 2024/1/15 17:30
 */
@Data
@AllArgsConstructor
@NoArgsConstructor
public class SoulInnResult<T> {

    private Boolean isSuccess;

    private String code;

    private String info;

    private T data;

    public static <T> SoulInnResult<T> success(T data) {
        return new SoulInnResult<>(true, ResponseCode.SUCCESS, data);
    }

    public static <T> SoulInnResult<T> fail() {
        return new SoulInnResult<>(false, ResponseCode.ERROR, null);
    }

    public static <T> SoulInnResult<T> fail(String info) {
        return new SoulInnResult<>(false, ResponseCode.ERROR.getCode(), info, null);
    }

    public static <T> SoulInnResult<T> fail(ResponseCode res) {
        return new SoulInnResult<>(false, res, null);
    }

    public SoulInnResult(Boolean isSuccess, ResponseCode res, T data) {
        this.isSuccess = isSuccess;
        this.code = res.getCode();
        this.info = res.getInfo();
        this.data = data;
    }

}
